//
//  Blob.m
//  Words2
//
//  Created by Mathieu on 3/10/06.
//  Copyright 2006 __MyCompanyName__. All rights reserved.
//

#import "Blob.h"


@implementation Blob
- (void)awakeFromInsert{
	[self setValue:[NSDate date] forKey:@"timeStamp"];
	//set our text blob to something default
	NSAttributedString *defaultString = [[NSAttributedString alloc] initWithString:@"Write your own definition here, and set your main definitions above."];
	[self setTextBlob:defaultString];
}

-(NSAttributedString *)textBlob{
	NSData *stringData;
	if ( textBlobCache == nil ){
		stringData = [self valueForKey:@"textBlobData"];
		if(stringData != nil){
			textBlobCache = [[NSKeyedUnarchiver unarchiveObjectWithData:stringData] retain];
		}
	}
	return textBlobCache;
}

-(void)setTextBlob:(NSAttributedString *)newTextBlob{
	if (textBlobCache != newTextBlob){
		[textBlobCache release];
		
		if(newTextBlob == nil){
			NSLog(@"newtextBlob was nil");
		}
		
		//cache and archive in managedObject.
		textBlobCache = [newTextBlob retain];
		NSData *textBlobData = [NSKeyedArchiver archivedDataWithRootObject:newTextBlob];
		[self setValue:textBlobData forKey:@"textBlobData"];
	}
}

@end
